<cfcomponent displayname="MyComponentTest"  extends="AbstractTest">  


  <cffunction name="testSendMessage" access="public">
	  <cfscript>
			var initialCount = variables.subethaSmtpService.getMessageCount();
			var curCount = 0;
			variables.subethaSmtpService.testmessage();
			curCount = variables.subethaSmtpService.getMessageCount(delayseconds=2);
			assertEquals(curcount,initialCount+1);
			variables.subethaSmtpService.clearMessages();
		</cfscript>
	</cffunction>

  <cffunction name="testFindMessageBySubject" access="public">
	  <cfscript>
			var curCount = 0;
			var randoms = randrange(1,999);
			var hits = 0;
			variables.subethaSmtpService.testmessage(delayseconds=2,subject="Randoms #randoms#");
			hits = variables.subethaSmtpService.findMessages(subject="Randoms #randoms#");
			assertEquals(1,arrayLen(hits));
			variables.subethaSmtpService.clearMessages();
		</cfscript>
	</cffunction>

  <cffunction name="testFindMessageBySender" access="public">
	  <cfscript>
			var curCount = 0;
			var randoms = randrange(1,999);
			var hits = 0;
			variables.subethaSmtpService.testmessage(delayseconds=2,subject="Randoms #randoms#");
			hits = variables.subethaSmtpService.findMessages(subject="Randoms #randoms#");
			assertEquals(1,arrayLen(hits));
			variables.subethaSmtpService.clearMessages();
		</cfscript>
	</cffunction>

  <cffunction name="testFindDeleteMessages" access="public">
	  <cfscript>
			var curCount = 0;
			var randoms = randrange(1,999);
			var hits = 0;
			variables.subethaSmtpService.testmessage(delayseconds=2,subject="Randoms #randoms#");
			variables.subethaSmtpService.testmessage(delayseconds=2,subject="Randoms #randoms#2");
			hits = variables.subethaSmtpService.findMessages(subject="Randoms");
			debug(arraylen(hits));
			variables.subethaSmtpService.deleteFoundMessages(hits);
			hits = variables.subethaSmtpService.findMessages(subject="Randoms");
			assertEquals(0,arrayLen(hits));
		</cfscript>
	</cffunction>

  <cffunction name="testClearMessages" access="public">
	  <cfscript>
			var curCount = 0;
			var randoms = randrange(1,999);
			var hits = 0;
			variables.subethaSmtpService.testmessage(delayseconds=2,subject="Randoms #randoms#");
			variables.subethaSmtpService.testmessage(delayseconds=2,subject="Randoms #randoms#2");
			variables.subethaSmtpService.clearMessages();
			hits = variables.subethaSmtpService.getMessages();
			assertEquals(0,arrayLen(hits));
		</cfscript>
	</cffunction>


  <cffunction name="testGetMessagesAsStruct" access="public">
	  <cfscript>
			var initialCount = variables.subethaSmtpService.getMessageCount();
			var curCount = 0;
			variables.subethaSmtpService.testmessage();
			curCount = variables.subethaSmtpService.getMessageCount(delayseconds=2);
			messages = variables.subethaSmtpService.getMessagesAsStruct();
			assertEquals(curcount,initialCount+1);
			variables.subethaSmtpService.clearMessages();
		</cfscript>
	</cffunction>

  <cffunction name="testDeleteMessage" access="public">
	  <cfscript>
			var initialCount = variables.subethaSmtpService.getMessageCount();
			var curCount = 0;
			var message = variables.subethaSmtpService.testmessage();
			var messages = variables.subethaSmtpService.getMessages(delayseconds=2);
			variables.subethaSmtpService.deleteMessage(messages[1].getMimeMessage().getMessageId());
			curCount = variables.subethaSmtpService.getMessageCount(delayseconds=2);
			assertEquals(curcount,initialCount);
		</cfscript>
	</cffunction>

</cfcomponent>
